import http from "../../../utils/https";
import imageUtils from "../../../utils/images"
Page({  
  data: {  
    // 租房数据（可自定义图片、字段）  
    rentalList: [  
      {  
        id: 1,  
        status: 0, // 0=出租中，1=已下架  
        imageUrl: '/images/article01.png', // 替换为实际图片路径  
        title: '整租 · 三室一厅一厨一卫',  
        area: '101㎡',  
        floor: '中楼层/共18层',  
        orientation: '南北通透',  
        price: '¥4500/月'  
      },  
      {  
        id: 2,  
        status: 0,  
        imageUrl: '/images/article01.png',  
        title: '合租 · 主卧带卫',  
        area: '28㎡',  
        floor: '高楼层/共32层',  
        orientation: '朝南',  
        price: '¥1800/月'  
      }  
    ]  
  },  

  // 租出下架（弹窗+状态切换）  
  handleRentOut(e) {  
    const id = e.currentTarget.dataset.id;  
    const residentId=wx.getStorageSync('residentId');
    wx.showModal({  
      title: '提示',  
      content: '确定下架此租房信息吗？',  
      success: (res) => {  
        if (res.confirm) {  

          http.put(`houseRental/houseRental/sale/${residentId}?status=0`,{
          }).then(resp=>{

          })
          .catch(err=>{
            console.log("请求失败");
          })

          this.setData({  
            rentalList: this.data.rentalList.map(item =>  
              item.id === id ? { ...item, del: 1 } : item  
            )  
          });  
          wx.showToast({ title: '已下架', icon: 'success' });  
        }  
      }  
    });  
  },  

  // 重新上架（状态切换）  
  handleRepost(e) {  
    const id = e.currentTarget.dataset.id;  
    const residentId=wx.getStorageSync('residentId');

    http.put(`houseRental/houseRental/sale/${residentId}?status=1`,{
    }).then(resp=>{

    })
    .catch(err=>{
      console.log("请求失败");
    })
    this.setData({  
      rentalList: this.data.rentalList.map(item =>  
        item.id === id ? { ...item, del: 0 } : item  
      )  
    });  
    wx.showToast({ title: '已重新上架', icon: 'success' });  
  },  

  // 编辑按钮（跳转编辑页，需提前创建页面）  
  handleEdit(e) {  
    const id = e.currentTarget.dataset.id;  
    wx.navigateTo({  
      url: '/service/pages/leaseHouseInfo/leaseHouseInfo?id=' + id, // 替换实际编辑页路径  
    });  
  },  

  // 悬浮按钮（跳转目标页）  
  handleAdd() {  
    wx.navigateTo({  
      url: '/service/pages/chooseLeaseHouse/chooseLeaseHouse', // 目标页路径  
    });  
  } ,
  //查询数据
  queryHouseRentalList(){
   const residentId = wx.getStorageSync('residentId')
    http.get(`houseRental/houseRental/byResidentId/${residentId}`).then(resp=>{
      this.setData({
       rentalList:resp.rows,
      })
    }).catch(err=>{
      console.log("请求失败");
    })
  },

  onLoad(){
    console.log("sss");
    this.queryHouseRentalList()
  }
})  